//购物车与结算
$(function(){
    let $shopcart = $(".shop-cart");
    let $parameter = $(location).attr("href").split("=")[1];
    switch($parameter){
        case "cart":
        console.log($parameter);
        cartInfo();
        break;
        case "settle":
        console.log($parameter);
        cartInfo();
        break;
    };
    function cartInfo(){
        let $cartinfo = $(`
            <div class="botnav">
                <div class="cart">
                    <p>合计：<span class="cart-num" style="color:red">￥0.00</span></p>
                    <p style="color:#999;font-size:.18rem">(共选择<span>0</span>个)</p>
                </div>
                <div class="settle">结算</div>
            </div>
        `);
        let $cartback = $("<div></div>");
        $shopcart.append($cartinfo);
        $shopcart.append($cartback);
        $cartinfo.css({
            "position":"fixed",
            "bottom":"0",
            "left":"0",
            "display": "flex",
            "width":"100%",
            "height":".7rem",
            "border-top":"1px solid #ddd",
            "z-index":"999"
        });
        $cartinfo.children("div").css({
            "position": "relative",
            "width":"50%",
            "text-align":"center",  
            "background": "#fff",
            "padding-top":".1rem"
        });
        $cartinfo.children(".settle").css({
            "line-height":".5rem",
            "color":"#fff",
            "background":"red"
        });
        $cartback.css({
            "width":"100%",
            "height":"5rem",
            "background":"url(../imgs/me/me_noorder.jpg) center/cover"
        });
        //弹窗
        let alertFlag = true;
        $cartinfo.children(".cart").click(function(){
            cartAlert();
        });
        $cartinfo.children(".settle").click(function(){
            cartAlert();
        });
        function cartAlert(){
            let $alert = $("<div>您的购物车还没有订单哦！</div>");
            if(alertFlag){
                $shopcart.append($alert);
            }
            //弹窗样式
            $alert.css({
                "position":"absolute",
                "top":".2rem",
                "left":"20%",
                "width":"60%",
                "height":".4rem",
                "background":"#d84c31",
                "color":"#fff",
                "text-align":"center",
                "line-height":".4rem",
                "border-radius":".04rem",
                "box-shadow":".02rem .02rem .06rem #000"
            });           
            setTimeout(function(){
                $alert.remove();
                alertFlag = true;
            },2000);
        };
    };
})